package com.heima.health.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.heima.health.entity.PageResult;
import com.heima.health.entity.QueryPageBean;
import com.heima.health.mapper.CheckItemMapper;
import com.heima.health.pojo.CheckItem;
import com.heima.health.service.CheckItemService;
import org.apache.commons.lang3.StringUtils;
import org.apache.dubbo.config.annotation.Service;
import org.springframework.transaction.annotation.Transactional;

@Service
@Transactional
public class CheckItemServiceImpl extends ServiceImpl<CheckItemMapper, CheckItem> implements CheckItemService {

    @Override
    public PageResult findPage(QueryPageBean queryPageBean) {
        Page pageData=null;

        QueryWrapper<CheckItem> wrapper=new QueryWrapper<>();
        wrapper.eq("IS_DELETE",0);

        if (StringUtils.isBlank(queryPageBean.getQueryString())){
            pageData=page(new Page(queryPageBean.getCurrentPage(),queryPageBean.getPageSize()),wrapper);
        }else {
            wrapper.like("NAME",queryPageBean.getQueryString());
            pageData=page(new Page(queryPageBean.getCurrentPage(),queryPageBean.getPageSize()),wrapper);
        }
        PageResult pageResult=new PageResult(pageData.getTotal(),pageData.getRecords());
        return pageResult;
    }
}
